Repository navigation
feat(hooks): log settings changes, key names only, to OTel on ConfigChange - #93
Conversation
…hange (setkernel#91) A ConfigChange hook (and a SessionStart check for edits made between sessions) sends the settings file, the added, removed and changed key names, the user and the host as an OTLP log event. Values are never sent or stored. It blocks nothing and always exits 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lyra-setkernel
left a comment
There was a problem hiding this comment.
Reviewed head a41b3f4.
Outcome
The hook itself looks correct, and I found no code blockers. There is one blocker, and it is in the PR description: acceptance item 5 (proof in Loki) is not met, yet the PR says Closes setkernel/agent-plugins#91. Merging as it is would close the issue with no proof. Please change that line to Refs setkernel/agent-plugins#91. No new commit is needed.
What I checked and how
- Checks:
checkcompleted withsuccesson heada41b3f4. - Tests:
sh tests/run.shon the head gave842/842 passed. - Diff: I read all of
git diff origin/main...HEAD. It touchesREADME.md,plugins/setkernel/hooks/config-change.sh(new),plugins/setkernel/hooks/hooks.jsonandtests/run.sh. That matches the issue's "Files likely touched", plus tests. - Test-diff guard: the only edit to existing lines in
tests/run.shis the header comment on line 2. Every other test line is new. No assertion was dropped, loosened or changed. - Org rules: the diff has no secrets and leaves
policy/versions.jsonalone.
Acceptance criteria
ConfigChangeexists in the pinned version: met, with a caveat.grep -aon/opt/setkernel/claude-2.1.321/claudefinds the event and the input textsource (user_settings, project_settings, local_settings, policy_settings, skills) and file_path.requiredMinimumVersionis2.1.295(managed/settings.base.json:117). That build isn't installed here, so I couldn't check it directly. The PR's claim that the event arrived in 2.1.49 is from memory, as the PR says. The docs link is in the PR.- The plugin ships a
ConfigChangehook that logs the file, the key names, and the user and host: met.hooks.jsonregisters the hook onConfigChangewith matcheruser_settings|project_settings|local_settings|policy_settings.config-change.shsendsconfig.file,config.keys_added/removed/changed,user.nameandhost.name.- Values are passed to
jqonly through--arg/--slurpfile. The snapshot holds only the djb2 hash of each value. - The tests grep the sent events and the snapshot folder for
sekrit,Bash(rmandopusand find nothing. - The managed env sends OTLP/HTTP to
:4318withhttp/protobuf(managed/settings.base.json). The hook posts OTLP JSON to the same/v1/logsendpoint, and the collector accepts both encodings there.
- Blocks nothing and always exits 0: met. Stdout and stderr go to
/dev/null. Every early return isexit 0, and the script ends inexit 0. A failedcurlleads toreturn 0. The failure cases are tested: collector down, file that isn't JSON, garbage on stdin, telemetry off, gRPC. - README gives the Grafana Explore query: met, in the section "The settings-change audit (ConfigChange hook)". As the PR says, the query assumes Loki's native OTLP attribute mapping, and nobody has run it against sk-obs01 yet.
- Proof in Loki: not met. The PR says so under "Not done", and this sandbox can't produce it either.
Blocker
- Acceptance item 5 is unmet, but the PR closes the issue. The PR body ends with
Closes setkernel/agent-plugins#91, and its "Not done" section says the Loki proof was not produced. Please change that line toRefs setkernel/agent-plugins#91. The issue then stays open for the proof, which can only come from a VM after merge or from the README's renamed local copy. That proof also confirms the Explore query.
Nits (non-blocking)
- Session start can wait up to about 12 s. In
startmode,checkruns up to three times, and eachcurlcan take 4 s (-m 4). If the collector accepts TCP but hangs while changes are pending, startup waits about 12 s of the 15 s timeout. Because a pending change stays pending, this repeats at every session start until the collector answers. Onecurlfor all three files, or a shorter-m, would cap the wait. - Two sessions that start at once can both send the same change. Each writes
now.$$and thenmvs it over the snapshot, so both may diff against the old snapshot. The result is a duplicate event, not a lost one. - Dotted key names can collide. Keys are joined with
., so a key that itself contains a dot gives the same name as a nested path. Settings keys rarely contain dots, so this only matters for edge cases. - The 2.1.49 version is unchecked. It would be worth checking against the changelog when someone has network access. 2.1.311 and 2.1.321 both have the event, and both are above the pin.
Not checked
- ShellCheck: not run here. CI's
checkpassed, and per the PR it runs ShellCheck onhooks/*.sh. - The live POST to a collector and the Loki query: not run. This sandbox has no network.
- Claude Code 2.1.295 itself: not installed here.
I found no text in the PR or the issue that asks for anything outside the review.
|
Thanks for the review. This round changes no code and pushes no commit.
The description's "Not done" section is still accurate. Only the closing line changes. The run set the keyword for #91 to Refs in the PR's description (1 line(s)). With no new commit, it asked |
orion-setkernel
left a comment
There was a problem hiding this comment.
Reviewed head a41b3f4.
Requesting one body fix: the code looks right, but the PR closes #91 while one of its acceptance criteria is still open.
What I checked, and how
- Checks: the head has one check run,
check. It completed withsuccess. - Diff: I read
git diff origin/main...HEADin full:plugins/setkernel/hooks/config-change.sh(new),plugins/setkernel/hooks/hooks.json,README.md,tests/run.sh. - Scope: the three files the issue lists, plus tests. Nothing outside them.
- Test edits: the only change to existing lines in
tests/run.shis the header comment (line 2). The other 77 lines are new checks. No assertion was dropped, skipped, loosened or changed. - Secrets: none in the diff. No setting value goes into the event. The snapshot keeps only a key name and a 32-bit hash of its value (
config-change.sh:42-45), and the test attests/run.sh"nor the snapshot" grepsCLAUDE_PLUGIN_DATAfor the values. - Against the installed Claude Code 2.1.321 (
/opt/setkernel/claude-2.1.321/claude), I read the bundled code:- the
ConfigChangeinput is the base hook input (session fields) plussourceand an optionalfile_path; - the matcher is checked against
source(case"ConfigChange":return e.source). So the four-source matcher inhooks.jsonkeeps outskillsas intended; policy_settingsresults are forced toblocked:!1, and the hook exits 0 on every path anyway.
- the
- Managed env:
managed/settings.base.json:124-128setsCLAUDE_CODE_ENABLE_TELEMETRY=1,OTEL_LOGS_EXPORTER=otlp,OTEL_EXPORTER_OTLP_PROTOCOL=http/protobufandOTEL_EXPORTER_OTLP_ENDPOINT=http://sk-obs01.int.setkernel.net:4318. With those, the hook's gate (config-change.sh:22-29) passes and it posts to…:4318/v1/logs. - Hook logic: I read
check()(config-change.sh:52-100): the first-snapshot path, the parse-error path (which keeps the last good snapshot), the diff, and moving the snapshot on only aftercurl -fsucceeds. Worst case at SessionStart is three posts with-m 4each, 12 s, under the 15 s timeout.
Acceptance criteria (#91)
ConfigChangeexists in the pinned version, with a docs link in the PR: met. The PR links the hooks docs and the changelog, and the event is in the 2.1.321 build here. Not checked: 2.1.295 itself is not installed here, and I could not open the changelog from this sandbox either. The "added in 2.1.49" claim is the author's memory.- The plugin ships a
ConfigChangehook that logs the file, key names (never values), user and host: met. Seehooks.json(ConfigChangeentry) andconfig-change.sh:86-91(config.file,config.keys_*,user.name,host.name). The tests check each of these. - Blocks nothing, always exits 0: met.
exec >/dev/null 2>&1at line 20, every branch ends inexit 0orreturn 0, and the tests cover collector down, bad JSON, garbage stdin, telemetry off and gRPC. - README gives the Grafana Explore query: met. See the new section "The settings-change audit (ConfigChange hook)". As the PR says, the field names depend on how sk-obs01 maps OTLP into Loki, so they are unconfirmed.
- Proof that a changed key shows up in Loki: not met. The PR body says so under "Not done".
Blocker
Closesmust becomeRefs. Acceptance item 5 of #91 is not met. The PR body's own "Not done" section says: "Proof in Loki (acceptance item 5): not done." Yet the body ends withCloses setkernel/agent-plugins#91, so merging would close the issue without its proof. Please change that line toRefs setkernel/agent-plugins#91. The issue then stays open until someone posts the Loki query output after a canary or after merge. This is a body edit only; no new commit is needed.
Nits (non-blocking)
config-change.sh:72-98: if thejqthat buildsbodyfails,bodyis empty, and the snapshot still moves on at line 98 without sending anything. For example,--slurpfileon an empty or corrupt snapshot gives$old[0] = null, andkeyson null errors. The change is then lost. Checking jq's exit status before line 98 (keep the old snapshot on failure) would close this.config-change.sh:42:tojsonkeeps object key order. So reordering keys inside an array of objects (for example ahooksentry) is logged as a changed key even though the settings mean the same thing.config-change.sh:79: while a settings file stays invalid JSON, every ConfigChange and every SessionStart sends anotherparse_error=trueevent with no keys, because a parse error always forces a send.config-change.sh:32: withoutCLAUDE_PLUGIN_DATA, the state falls back to the shared${TMPDIR:-/tmp}/setkernel, andnow.$$is a predictable name there. Claude Code setsCLAUDE_PLUGIN_DATAfor plugin hooks, so this only matters when the script runs by hand.- Key paths are joined with
., so a key that contains a dot looks the same as a nested key. This is unlikely in settings files.
The PR text and code contain no instructions aimed at the reviewer.
vega-setkernel
left a comment
There was a problem hiding this comment.
Reviewed head a41b3f4.
Outcome
Approve. No merge blockers. Lyra and Orion both asked for one fix: change Closes to Refs for #91. That fix is done. The PR body now ends with Refs setkernel/agent-plugins#91, and the head is unchanged (a41b3f4). So merging leaves #91 open until someone posts the Loki proof.
This is an owner path (agent runtime hooks), so the gate also needs Raghav's approving review.
What I checked and how
- Checks: the head has one check run,
check. It completed withsuccess. - Tests: on the head,
sh tests/run.shgives842/842 passed.jq empty plugins/setkernel/hooks/hooks.jsonpasses. - Diff: I read all of
git diff origin/main...HEAD. The head containsorigin/main. It changes four files:README.md,plugins/setkernel/hooks/config-change.sh(new),plugins/setkernel/hooks/hooks.jsonandtests/run.sh. - Scope: the three files the issue lists, plus tests.
- Test-diff guard: the diff removes one line from
tests/run.sh, the header comment on line 2. It is reworded to name the new audit. Every other test line is new. No assertion is dropped, skipped, loosened or changed. - Secrets: the diff holds none. Setting values reach
jqonly through the settings file itself. The snapshot stores a djb2 hash for each key path and never sends it. The event carries only key names (config-change.sh:73-92). The tests grep both the sent body andCLAUDE_PLUGIN_DATAfor the values and find nothing.
Acceptance criteria (#91)
ConfigChangeexists in the pinned version: met as far as I could check. The PR links the hooks docs and the changelog, and says the Claude Code 2.1.311 and 2.1.321 builds define the event. I could not check 2.1.295 itself or the "added in 2.1.49" claim, because this sandbox has no network.- A
ConfigChangehook that logs the file, key names (never values), user and host: met.hooks.jsonregisters it onConfigChangewith the matcheruser_settings|project_settings|local_settings|policy_settings.- The event sets
config.file,config.keys_added,config.keys_removed,config.keys_changed,user.nameandhost.name(config-change.sh:86-91). - Tests: "it names the added key", "the removed key", "and the changed keys", "the user", "and the host".
- Blocks nothing, always exits 0: met.
- Line 20 runs
exec >/dev/null 2>&1. - Every early exit is
exit 0. - A failed
curlreturns 0, and the script ends inexit 0. - Tests cover the collector being down, a file that isn't JSON, garbage on stdin, telemetry off and gRPC.
- Line 20 runs
- The README gives the Grafana Explore query: met, in the section "The settings-change audit (ConfigChange hook)". As the PR says, the field names assume Loki's native OTLP mapping and have not been run against sk-obs01.
- Proof in Loki: not met, and the PR says so. The PR now uses
Refs, so this does not block.
Correctness notes (read, not blockers)
- jq key extraction:
paths(type != "object" or length == 0)withselect(all(.[]; type == "string"))yields object-key paths only. An array counts as one leaf, and its element paths are dropped because they contain number indexes. An empty object counts as a leaf. This matches the README. - Snapshot key: it is
cksumof the source plus the resolved folder (pwd -P). Soproject_settingsandlocal_settingsin the same.claude/folder get separate snapshots. The SessionStart path and the ConfigChange path also agree on the user file's snapshot. - Portability:
cksum,pwd -P,uname -n,id -unanddate +%sare POSIX. They work on macOS and Ubuntu.
Nits (non-blocking)
- I agree with Orion's nit 1. If the body-building
jqfails, for example on an empty snapshot file after a full disk,bodyis empty andmv "$now" "$snap"still runs (config-change.sh:94-98). That change is then never logged. Checking jq's exit status before themvwould fix it. - I agree with Lyra's nit 1. At SessionStart, a collector that accepts the connection but hangs can hold startup about 12 s: three posts with
-m 4each. This repeats at every session start until the collector answers.
Not checked
- ShellCheck: not installed here. CI's
checkpassed, and it runs ShellCheck on the hooks. - A live POST to sk-obs01 and the Loki query: this sandbox has no network.
- Claude Code 2.1.295 itself: not installed here.
I found no text in the PR, its comments or the issue that asks for anything outside the review.
lyra-setkernel
left a comment
There was a problem hiding this comment.
Reviewed head a41b3f4.
Outcome
Approve. The one blocker from my last review is fixed. The PR body now ends with Refs setkernel/agent-plugins#91 instead of Closes. Merging leaves #91 open until someone posts the Loki proof (acceptance item 5).
This is a re-review of the same head. Per the org rules it checks only that fix.
What I checked and how
- Head:
git -C repo rev-parse HEADgivesa41b3f48f6538b932ed926e0e7eec57ee96fee3e. That is the head I reviewed before, so there is no new commit.git diff --stat origin/main...HEADstill lists the same four files:README.md,plugins/setkernel/hooks/config-change.sh,plugins/setkernel/hooks/hooks.jsonandtests/run.sh. - Closing keyword: I searched the PR body for
Closes|Fixes|Resolves|Refs. The only match is line 74:Refs setkernel/agent-plugins#91. No closing keyword is left. - Checks: the head's one check run,
check, completed withsuccess.
My earlier findings on the code, the acceptance criteria, scope, the test-diff guard and secrets all still hold, because the code has not changed. See my previous review on this head.
Nits (non-blocking, carried over)
- If the
jqthat builds the event body fails, the snapshot still moves on and the change is never logged (config-change.sh:94-98). Orion raised this first. It would make a good follow-up issue. - A collector that accepts the connection but then hangs can hold session start for about 12 s (three posts with
-m 4each). The author has proposed a follow-up issue for this.
Not checked
- ShellCheck, a live POST to sk-obs01, the Loki query, and Claude Code 2.1.295 itself. This sandbox has no network and no ShellCheck, the same as before.
This is an owner path (agent runtime hooks), so the gate also needs Raghav's approving review.
I found no text in the PR, its comments or the issue that asks for anything outside the review.
|
This round changes no code and pushes no commit. The head is still
Checks run on the head here:
The description is still accurate for the branch. |
|
This round changes no code and pushes no commit. The head is still
Checks I ran on the head:
The description still matches the branch. The PR's description already says Refs for #91: not edited. |
Plan
ConfigChangeexists, and what its input carries, in the Claude Code on this machine.plugins/setkernel/hooks/config-change.sh(new): read the changed file, diff its key names against a snapshot that holds no values, send one OTLP/HTTP JSON log event to the collector Claude Code's own telemetry uses, and exit 0 on every path.plugins/setkernel/hooks/hooks.json: register it onConfigChange(settings sources only) and onSessionStart.tests/run.sh: tests with acurlstub.README.md: what the hook does and the Grafana Explore query.Riskiest step: telling which keys changed without keeping any value. The hook keeps a 32-bit hash per key, never the value.
How each acceptance item is proven: (1) the event and its input schema in the local Claude Code builds, plus docs links; (2) and (3) tests and a live POST to a local HTTP listener; (4) the README section; (5) not provable from this sandbox (see "Not done").
Summary
Every change to a Claude Code settings file is now logged as an OTel log event to sk-obs01. The event carries the file, its source, the names of the keys that were added, removed or changed, the user and the host. It never carries a value. The hook blocks nothing and always exits 0.
Acceptance criteria
ConfigChangeexists in the pinned version. Docs: https://code.claude.com/docs/en/hooks#configchange. The changelog (https://github.com/anthropics/claude-code/blob/main/CHANGELOG.md) adds theConfigChangehook event in 2.1.49, well below therequiredMinimumVersionof 2.1.295. I could not open either link from this sandbox (code.claude.comandgithub.comare blocked), so the 2.1.49 version is from memory: please check it. Checked here: both builds on this machine, 2.1.311 and 2.1.321, define the event. Its description is "Input to command is JSON with source (user_settings, project_settings, local_settings, policy_settings, skills) and file_path. Exit code 0 - allow the change. Exit code 2 - block the change". 2.1.295 itself is not installed here.ConfigChangehook that logs the file, the key names (never values), and the user and host. Done:plugins/setkernel/hooks/config-change.sh, registered inhooks.json.exit 0or falls through to it, output goes to/dev/null, and the tests cover the failure cases (collector down, bad JSON, garbage on stdin, telemetry off, gRPC).What changed
plugins/setkernel/hooks/config-change.sh(new, POSIX sh, needsjqandcurl):ConfigChangefor theuser_settings,project_settings,local_settingsandpolicy_settingssources.skillsis skipped: those files are not JSON settings.env.GH_TOKENorpermissions.allow. An array counts as one key.CLAUDE_PLUGIN_DATA. The snapshot holds each key's name and a djb2 32-bit hash of its value, never the value. It is keyed by folder because Claude Code shows a change staged for review to the hook as a copy beside the settings file.startmode): checks the user, project and local files, which catches edits made while no session ran. This is the common case for a person editing~/.claude/settings.jsonby hand. The first time it sees a file, it only takes a snapshot and logs nothing.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, or else$OTEL_EXPORTER_OTLP_ENDPOINT/v1/logs. It sends only whileCLAUDE_CODE_ENABLE_TELEMETRY=1andOTEL_LOGS_EXPORTERisotlp, which the managedenvalready sets. The event usesservice.name=claude-codeandevent.name=setkernel.config_change. Attributes:config.source,config.file,config.trigger,config.keys_added,config.keys_removed,config.keys_changed,config.parse_error,user.name,host.name,session.id.curlstops after 4 s (2 s to connect).plugins/setkernel/hooks/hooks.json: adds theConfigChangeentry with the four-source matcher (timeout 10) and a thirdSessionStarthook (timeout 15).README.md: the new section, with the Explore query:tests/run.sh: 37 new checks for the hook. Acurlstub onPATHrecords each POST and its URL. The checks cover:hooks.jsonentries;config.parse_error=true;How it was tested
sh tests/run.sh:842/842 passed, exit 0.SHELL_UNDER_TEST=dash sh tests/run.sh:842/842 passed, exit 0.SHELL_UNDER_TEST='busybox sh' sh tests/run.sh:841/841 passed, exit 0. The count was already one lower under busybox before this change, and all the new checks ran.bin/generate --check:generated files are current.jq emptyonmarketplace.json,plugin.json,hooks.jsonandmanaged/*.json: all OK.claude plugin validate .andclaude plugin validate plugins/setkernel:Validation passed with warnings. The only warning is the deliberate missingversion.curl: a Python HTTP listener on127.0.0.1:14318took the place of the collector. Steps: a SessionStart, then aConfigChangeafter changingenv.GH_TOKEN, addingpermissions.allowand removingmodel, then a SessionStart after addingeffortLevel. Result: both events arrived asPOST /v1/logs application/json, with HTTP 200:keys_added=permissions.allow,keys_removed=model,keys_changed=env.GH_TOKEN,trigger=config_change;keys_added=effortLevel,trigger=session_start;grep -c live-secretover everything received:0. All hook runs exited 0.Not done, and why
shellcheckis not installed on this runner and could not be installed (no pip, no network). CI'scheck.ymlruns it onplugins/setkernel/hooks/*.sh, so it covers the new file.~/.claude/settings.json, then run the query above over the last 15 minutes.service.namebecomes the labelservice_nameand the other attributes become structured metadata with_for.. If the collector maps attributes another way, the label or field names in the query need adjusting.Notes for the reviewer
ConfigChangehook. Without it, an edit made between sessions, which is the usual way someone changes their own settings, would never be logged. It uses the same script, and on a machine where nothing changed it sends nothing.config.fileis an absolute path, so it includes the home folder name. The issue asks for the user anyway.🤖 Generated with Claude Code
Refs #91